﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataCore;
using DataCore.DomainObjects;

namespace ExpertSystem.Views
{
    public partial class CreateNewClassView : Form
    {
        private MetaClass _metaClass;
        private List<AtributeType> _atributeTypes;
        public CreateNewClassView()
        {
            _metaClass = new MetaClass("");
            InitializeComponent();
        }


        public CreateNewClassView(List<AtributeType> atributeTypes,MetaClass metaClass)
        {
            InitializeComponent();
            _atributeTypes = atributeTypes;
            comboBox1.Items.AddRange(atributeTypes.ToArray());
            _metaClass = metaClass;
        }
        private void Redraw()
        {
            dataGridView1.Rows.Clear();
            foreach (Atribute atribute in _metaClass.Atributes)
            {
                dataGridView1.Rows.Add();
                DataGridViewRow Row = dataGridView1.Rows[dataGridView1.Rows.Count - 1];
                Row.Cells[0].Value = atribute.Name;
                Row.Cells[1].Value = atribute.AtributeType.TypeName;
            }
        }

        private void CreateNewClassView_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Atribute atribute = new Atribute((AtributeType)comboBox1.SelectedItem, textBox1.Text);
            _metaClass.AddAtribute(atribute);
            Redraw();
            
        }
    }
}
